/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package Robot.Sensors;

import Utils.*;
/**
 *
 * @author alejo
 */
public class VPSensor extends Thread {

    VPSocketStream conn;

    //the size of the image.
    //TODO: EStos parametros deberian ser pedidos por protocolo a la aplicacion
    //C/C++
    private int imgWidth;
    private int imgHeight;

    private int msgNum;
    private int vpX;
    private int vpY;
    private int vpFid;




    public VPSensor(int imgWidth, int imgHeight, String ipAddr, int port)
    {
        this.imgWidth = imgWidth;
        this.imgHeight = imgHeight;
        conn = new VPSocketStream(ipAddr,port);

    }

    public int getVpX()
    {
        return this.vpX;
    }

    public int getVpY()
    {
        return this.vpY;
    }

    public int getVpFid()
    {
        return this.vpFid;
    }


    public int getWidth()
    {
        return this.imgWidth;
    }

    public int getHeight()
    {
        return this.imgHeight;
    }

    public int getMsgNum()
    {
        return this.msgNum;
    }

    public void run()
    {
        while(true)
        {
            try
            {
                conn.readObject();
            }
            catch(Exception e)
            {
                e.printStackTrace();
            }

            this.msgNum = conn.getMsgNum();
            this.vpX = conn.getX();
            this.vpY = conn.getY();
            this.vpFid = conn.getFidelity();


            //System.out.println(conn.toString());

            try
            {
                this.sleep(100);
            }
            catch(Exception e)
            {
                e.printStackTrace();
            }
        }


    }

    public Vector2d getVanishPoint()
    {
        return new Vector2d(vpX,vpY,Vector2d.MODE_XY);
    }

}
